<?php
/**
 * The Logger class
 *
 */
class Logger
{
	/**
	 * The log file path
	 * 
	 * @var string 
	 */
	static protected $logFile;

	/**
	 * Enter description here...
	 * 
	 * @param integer $errorLevel 
	 * @param integer $errorCode 
	 * @param string $description 
	 * @param mixed $data 
	 * @return void 
	 * @example log(1, 500, 'Database server has gone down.', array('current_user' => 'root'))
	 */
	static public function log($errorLevel, $errorCode, $description, $data)
	{
		$time = time();
		$ip = Input::server('REMOTE_ADDR');
		$referer = Input::server('HTTP_REFERER');
		$stack = json_encode(debug_backtrace());
		$data = json_encode($data);
		$str = "\`~$errorCode~\` \`~$errorLevel~\` \`~$description~\` \`~$ip~\` \`~$time~\` \`~$referer~\` \`~$data~\` \`~$stack~\`";
		$cmd = 'echo "' . $str . '" >> ' . self::$logFile;
		`$cmd`;
	}

	/**
	 * Set default log file path
	 * 
	 * @param string $filePath 
	 * @return void 
	 */
	static public function setDefaultLogFile($filePath)
	{
		self::$logFile = $filePath;
	}
}
